package com.ysdzz.hadoop;

import java.io.IOException;
import java.util.List;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.google.common.base.Splitter;

public class UserCityMapper extends Mapper<LongWritable, Text, Text, LongWritable> {

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
			throws IOException, InterruptedException {
		String line = value.toString();
		List<String> list = Splitter.on("\t").splitToList(line);
		if(null!=list && list.size()==21){
			String outkey = list.get(6);
			if(outkey.endsWith("市")){
				outkey = outkey.substring(0, outkey.length()-1);
				System.out.println(outkey);
			}
			context.write(new Text(outkey), new LongWritable(1l));
		}
	}
	
}
